<?php

class Video extends Controller {

    public function videolist() {        
        $this->load->model('video_model');
        $this->load->library("pagination");
        $config = array();
        $config["base_url"] = base_url() ."secu/video/videolist/";
        $config["total_rows"] = $this->video_model->get_video_list_count();
        $config["per_page"] = 10;
        $config["uri_segment"] = 4;
        $this->pagination->initialize($config);
        $page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
        $data["pagination"] = $this->pagination->create_links();
        $videolist=$this->video_model->get_video_list($config["per_page"], $page);
        $data["videolist"]=$videolist;
        $this->template->set('controller', $this);
        $this->template->set('title', "login");
        $this->template->load_partial('admintemplate','video/videolist',$data);

    }

   public function addvideo() {
        $data["partnerlang"]=$this->config->item("partnerlang");
       // $this->template->load('admintemplate','admin/video',$data);
        $this->template->set('controller', $this);
        $this->template->set('title', "login");
        $this->template->load_partial('admintemplate','video/videos',$data);
    }

    public function doaddvideo()
    {
          $validate_video = array(
                array( 'field' => 'video_code',
                       'field' => 'video_code',
                       'label' => 'Title',
                       'rules' => 'required')
            );
        $videodetails=array();
             $videodetails = array( 'videodetails' => array(
             "video_title"  =>$this->input->post('video_title')
             ,"video_code"  =>$this->input->post('video_code')
             ,"default_video"=>$this->input->post('default_video')
             ,"last_updated"=>date('Y-m-d H:i:s')
             ,"status"=>$this->input->post('status')
                     ));
          //   print_r($_POST);exit;
            $this->session->set_userdata($videodetails);
            $this->form_validation->set_error_delimiters('<div class="alert">', '</div>');
            $this->form_validation->set_rules($validate_video);

            if ($this->form_validation->run() == FALSE) {
                $this->template->set('controller', $this);
                $this->template->set('title', "login");
                $this->template->load_partial('admintemplate', 'video/videos',$data);

            } else  {
              //$this->template->set('product_header', 'Admin Home');
              $this->load->model('video_model');
              $this->video_model->addnewvideo($videodetails["videodetails"]);
              redirect('secu/video/videolist');
              //$this->load->model('user_security');
            }

    }
    
    public function videoedit()
    {
        $videoid= $this->uri->segment(5);
    //    echo "****".$videoid;exit;
        $data["partnerlang"]=$this->config->item("partnerlang");
        $this->load->model('video_model');
        $videodetails=array();
        $videodetails=$this->video_model->get_video_details($videoid);        
             $videodetails = array(
             "id"  =>$videodetails["id"]
             ,"video_title"  =>$videodetails["video_title"]
             ,"video_code"  =>$videodetails["video_code"]
             ,"default_video"=>$videodetails["default_video"]
             ,"status"=>$videodetails["status"]
                     );
             $this->session->set_userdata($videodetails);
             print_r($videodetails);
        $data["videodetails"]=$videodetails;
        $this->template->load('admintemplate','secu/video/videos',$data);
    }

    public function doeditvideo()
    {
          $validate_video = array(
                array( 'field' => 'video_title',
                       'field' => 'video_code',
                       'label' => 'Title',
                       'rules' => 'required')
            );
        $videodetails=array();
             $videodetails = array( 'videodetails' => array(
             "id"=>$this->input->post('id')
             ,"video_title"  =>$this->input->post('video_title')
             ,"video_code"  =>$this->input->post('video_code')
             ,"default_video"=>$this->input->post('default_video')
             ,"last_updated"=>date('Y-m-d H:i:s')
             ,"status"=>$this->input->post('status')
                     ));
            //echo date('Y-m-d H:i:s');exit;
            $this->session->set_userdata($videodetails);
            $this->form_validation->set_error_delimiters('<div class="alert">', '</div>');
            $this->form_validation->set_rules($validate_video);

            if ($this->form_validation->run() == FALSE) {
                $this->template->set('controller', $this);
                $this->template->set('title', "login");
                $this->template->load_partial('admintemplate','video/videos',$data);
             //   $this->template->load('admintemplate', 'admin/videoomodation',$data);

            } else  {
              //$this->template->set('product_header', 'Admin Home');
              $this->load->model('video_model');
              $this->video_model->doeditvideo($videodetails["videodetails"]);
              redirect('secu/video/videolist');
              //$this->load->model('user_security');
            }

    }

     public function videodelete()
    {

              //$this->template->set('product_header', 'Admin Home');
               $videoid= $this->uri->segment(5);
              $this->load->model('video_model');
              $this->video_model->deletevideo($videoid);
              redirect('secu/video/videolist');
              //$this->load->model('user_security');
      }
}   
?>
